package com.nb.nbbase2.exception;
import com.nb.nbbase2.model.Result;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BizException.class)
    public Result handleBizException(BizException ex) {
        return Result.fail(ex.getCode(),ex.getMessage());
    }

    // 你可以在这里添加更多的@ExceptionHandler方法来处理其他类型的异常

    // 例如，处理所有未捕获的异常
    @ExceptionHandler(Exception.class)
    public Result handleAllExceptions(Exception ex) {
        return Result.fail(500,"服务器错误，请联系管理员");
    }
}
